//
//  AROnlineCountView.m
//  AriseSamePro
//
//  Created by 包日守 on 15/10/24.
//  Copyright © 2015年 Arise. All rights reserved.
//

#import "AROnlineCountView.h"

@implementation AROnlineCountView


- (id) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 30, 30)];
        [self addSubview:imageView];
        imageView.image = [[UIImage imageNamed:@"channel_info_white@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        
    }
    
    return self;
}


- (void) setCount:(int)count
{
    for (UIView *view in self.subviews) {
        [view removeFromSuperview];
    }
    
    
    UIImageView *bottmImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [self addSubview:bottmImageV];
    /*
     bottmImageV.image = [[UIImage imageNamed:@"channe_online_people_9_below_white@2x"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
     
     UIImageView *topImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
     [self.rightView addSubview:topImageV];
     */
    
    if (count < 10) {
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
        [self addSubview:imageV];
        imageV.image = [[UIImage imageNamed:@"channe_online_people_single_white@2x"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 35)];
        label.text = [NSString stringWithFormat:@"%d",count];
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont systemFontOfSize:14];
        label.textAlignment = NSTextAlignmentCenter;
        
        [self addSubview:imageV];
        [imageV addSubview:label];
        
        
        
    }
    else
    {
        
        CGRect contentRect = [[NSString stringWithFormat:@"%d",count] boundingRectWithSize:CGSizeMake(300, 35) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil];
        
        UIImageView *imageVBottom = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, contentRect.size.width + 20, 40)];
        [self addSubview:imageVBottom];
        imageVBottom.image = [[UIImage imageNamed:@"channe_online_people_9_below_white@2x"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        
        
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, contentRect.size.width, 35)];
        label.text = [NSString stringWithFormat:@"%d",count];
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont systemFontOfSize:14];
        label.textAlignment = NSTextAlignmentCenter;
        
        UIImageView *imageVTop = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, contentRect.size.width + 20, 40)];
        [self addSubview:imageVTop];
        
        imageVTop.image = [[[UIImage imageNamed:@"channe_online_people_9_white@2x"] imageWithAlignmentRectInsets:UIEdgeInsetsMake(0, 5, 0, 5) ] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        
        [imageVTop addSubview:label];
        
    }


}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
